feat(tracer)!: default span names to operation name for OTel compliance#82
Open
obitech wants to merge 1 commit into
Open
feat(tracer)!: default span names to operation name for OTel compliance#82obitech wants to merge 1 commit into
obitech wants to merge 1 commit into
Conversation
Span names now default to the low-cardinality operation name (e.g. "SELECT") instead of the raw SQL statement, following the OpenTelemetry database span conventions. The full statement remains available in the db.query.text attribute. The previous default embedded the raw SQL in the span name, prefixed with "query"/"prepare"/"batch query". Because redaction and masking rules are typically applied to attributes rather than span names, sensitive data in a statement could leak into telemetry through the name (closes #68). BREAKING CHANGE: the default span name changes from the full SQL statement to the operation name, and the "query"/"prepare"/"batch query" prefix is no longer added by default. To restore the previous behavior exactly: otelpgx.NewTracer( otelpgx.WithFullSQLInSpanName(), otelpgx.WithQuerySpanNamePrefix(), ) WithTrimSQLInSpanName and WithDisableQuerySpanNamePrefix are deprecated; their effects are now the defaults.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Span names now default to the low-cardinality operation name (e.g.
SELECT) instead of the raw SQL statement, following the OpenTelemetry database span conventions. The full statement remains available in thedb.query.textattribute.Closes #68.
Motivation
The previous default embedded the raw SQL in the span name, prefixed with
query/prepare/batch query. Because redaction and masking rules are typically applied to attributes (likedb.query.text) rather than to span names, sensitive data inside a statement could leak into telemetry through the name — the security incident reported in #68. The OTel conventions also require span names to be low cardinality, which the raw statement violates.What changed
tracer.go: span name is now built from the operation name by default; the operation name is computed once per query and shared between thedb.operation.nameattribute and the span name (a newspanNamehelper, replacing three duplicated inline blocks).options.go:WithFullSQLInSpanName()— opt back into the full SQL statement as the span name (discouraged; can leak data).WithQuerySpanNamePrefix()— opt back into thequery/prepare/batch queryprefix.WithTrimSQLInSpanName()andWithDisableQuerySpanNamePrefix()— their effects are now the defaults.tracer_test.go: addedTestTracer_spanNameasserting span names directly across query/prepare/batch and all option combinations (previously only attributes were asserted).Breaking change
The default span name changes from the full SQL statement to the operation name, and the
query/prepare/batch queryprefix is no longer added by default. To restore the previous behavior exactly: